﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wsy.ext.Devlib.ExtensionMethods
{
    public static class StringExt
    {
        public static int ToInt(this string src)
        {
            int tmp = 0;
            int.TryParse(src, out tmp);
            return tmp;
        }
        public static long ToLong(this string src)
        {
            long tmp = 0;
            long.TryParse(src, out tmp);
            return tmp;
        }
        public static float ToFloat(this string src)
        {
            float tmp = 0;
            float.TryParse(src, out tmp);
            return tmp;
        }
        public static double ToDouble(this string src)
        {
            double tmp = 0;
            double.TryParse(src, out tmp);
            return tmp;
        }
        public static decimal ToDecimal(this string src)
        {
            decimal tmp = 0;
            decimal.TryParse(src, out tmp);
            return tmp;
        }


        public static string RunCmd(this string cmdtext)
        {
            //string cmdtext = "taskkill /F /IM wps.exe";
            Process p = new Process();
            //设定程序名
            p.StartInfo.FileName = "cmd.exe";
            //关闭shell的使用
            p.StartInfo.UseShellExecute = false;
            //重新定向标准输入
            p.StartInfo.RedirectStandardInput = true;
            //重新定向标准输出
            p.StartInfo.RedirectStandardOutput = true;
            //设置不显示窗口
            p.StartInfo.CreateNoWindow = true;
            //执行ver命令
            p.Start();
            p.StandardInput.WriteLine(cmdtext);
            p.StandardInput.WriteLine("exit");
            //返还DOS信息
            string strinfo = p.StandardOutput.ReadToEnd();
            return strinfo;
        }


      

     }
}
